//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __SHADOW_H__
#define __SHADOW_H__

#include "eventqueue.h"
#include "linknode.h"
#include "keyboard.h"
#include "mouse.h"

class CShadow: public DLinkNode
{
public:
    Int32 Transform2RelativeX(Int32 absoluteX) {
            assert (absoluteX >= m_posX);
            return (absoluteX - m_posX);
          }
    Int32 Transform2RelativeY(Int32 absoluteY) {
            assert (absoluteY >= m_posY);
            return (absoluteY - m_posY);
          }

    CKeyboard * GetKeyboard();
    CMouse    * GetMouse();

    Boolean GetFocused(Int32 x, Int32 y);

public:
    CShadow(Int32 x,
            Int32 y,
            Int32 width,
            Int32 height,
            Int32 environmentId)
          : m_posX(x), m_posY(y),
            m_width(width),
            m_height(height),
            m_environmentId(environmentId){DLinkNode::Initialize();}

    ~CShadow(){}

private:
    CEventQueue * m_pKeyboard;
    CEventQueue * m_pMouse;

    Int32 m_posX;
    Int32 m_posY;
    Int32 m_width;
    Int32 m_height;

    Int32 m_environmentId;
};


class CShadowManager
{
public:
    CShadow * GetFocus(Int32 x, Int32 y);
    CShadow * GetFocus();

    void      AddShadow(CShadow * pShadow);
    void      RemoveShadow(CShadow * pShadow);

public:
    CShadowManager() { m_shadowList.Initialize(); assert(m_shadowList.IsEmpty());}
    ~CShadowManager() {}

private:
    //RTL_CRITICAL_SECTION m_hLock;
    DLinkNode m_shadowList;
};

EXTERN CShadowManager * GetShadowManager();

#endif //__SHADOW_H__

